package com.shuqi.model.parse.parser;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import com.shuqi.model.parse.HandlerBase;

public class LoginAccountParser extends HandlerBase {
    private LoginAccountParserInfo info;

    @Override
    public void startDocument() throws SAXException {
        super.startDocument();
        info = new LoginAccountParserInfo();
    }


    @Override
    public void startElement(String uri, String localName, String name, Attributes attrs)
            throws SAXException {
        if (localName.equals("items")) {
            try {
                info.resultCode = Integer.valueOf(isNull(attrs, "status"));
                info.message = isNull(attrs, "message");
                info.lastimei = isNull(attrs, "lastimei");
                info.lasttime = isNull(attrs, "lasttime");
                info.session = isNull(attrs, "session");
                info.email = isNull(attrs, "email");
                info.mobile = isNull(attrs, "mobile");
                info.nickname = isNull(attrs, "nickname");
                info.uid = isNull(attrs, "userid");
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (localName.equals("tp")) {
            int type = Integer.valueOf(isNull(attrs, "type"));
            if (type == 1) {
                // 表示新浪
                info.sinaId = isNull(attrs, "id");
                info.sinanickname = isNull(attrs, "nickname");
            }
        } else if (localName.equals("account"))// 错误的时候node不一样
        {
            info.resultCode = Integer.valueOf(isNull(attrs, "status"));
            info.message = isNull(attrs, "info");
        }
    }

    @Override
    public LoginAccountParserInfo getParsedData() {
        return info;
    }

    public static class LoginAccountParserInfo {

        public int resultCode;
        // 对应的成功或者错误信息
        public String message;
        // 上一次登录使用的IMEI串号
        public String lastimei;
        // 上一次登录时间
        public String lasttime;
        // 用于标识用户身份（计算书龄和进广场时用到）
        public String session;
        // 第三方账户类型(目前只有两种,新浪微博(type="1")和腾讯QQ(type="2"))
        public int type;
        // 第三方账户的key
        public String sinaId;
        // 代表第三方账户的昵称
        public String sinanickname;

        public String nickname;

        public String email;

        public String mobile;

        public String uid;
    }
}
